const { query } = require("../db/query")
module.exports = {
  // 获取首页轮播图数据
  getCarousel: async (limit) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from carousel limit 0,?", [limit])
  },
  // 获取养宠达人列表
  getPetTalentList: async (limit) => {
    // 调用query发送sql语句到mysql进行注册用户
    // 获取养宠达人id列表
    // return await query("SELECT * FROM `user` WHERE `user_id` IN (SELECT `user`.user_id FROM `petinformation`,`user` WHERE `user`.user_id = `petinformation`.user_id GROUP BY `user`.user_id ORDER BY SUM(`pet_collect_count`) DESC);")

    // 通过用户积分字段获取养宠达人用户列表
    if (limit == "all") {
      return await query("select * from user order by user_integral desc")
    }
    return await query("select * from user order by user_integral desc limit 0,?", [limit])
  },
  // 获取人气推荐列表
  getRecommendList: async (limit) => {
    if (limit == "all") {
      return await query("SELECT petinformation.*,`user`.user_name FROM petinformation,`user` WHERE petinformation.user_id = `user`.user_id ORDER BY petinformation.pet_collect_count DESC;")
    }
    // 调用query发送sql语句到mysql进行注册用户
    return await query("SELECT petinformation.*,`user`.user_name FROM petinformation,`user` WHERE petinformation.user_id = `user`.user_id ORDER BY petinformation.pet_collect_count DESC LIMIT 0,?;", [limit])
  },
  // 根据品种搜索宠物列表
  searchList: async (pet_variety) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query(`SELECT * FROM petinformation WHERE pet_variety LIKE '%${pet_variety}%';`)
  },
}